package models

import (
	"fitness-srv/basic/config"
	"gorm.io/gorm"
	"time"
)

// 预约表
type Reservation struct {
	gorm.Model
	UserId          int        `json:"user_id" gorm:"type:int;comment:'用户id'"`
	CourserId       int        `json:"courser_id" gorm:"type:int;comment:'课程id'"`
	CoachId         int        `json:"coach_id" gorm:"type:int;comment:'教练id'"`
	EquipmentId     int        `json:"equipment_id" gorm:"type:int;comment:'器材id'"`
	ReservationSn   string     `json:"reservation_sn" gorm:"type:varchar(50);comment:'预约编号'"`
	Price           float64    `json:"price" gorm:"type:decimal(10,2);comment:'价格'"`
	ReservationTime *time.Time `json:"reservation_time" gorm:"type:datetime;comment:'预约时间'"`
	Number          int        `json:"number" gorm:"type:int;comment:'数量'"`
	Status          int        `json:"status" gorm:"type:int;comment:'状态 1-已开始 2-已结束 3-已取消'"`
}

func (r *Reservation) TableName() string {
	return "reservation"
}

func (r *Reservation) AddReservation() error {
	return config.DB.Create(&r).Error
}

func (r *Reservation) GetReservation(id int64) error {
	return config.DB.Model(&Reservation{}).Where("id = ?", id).Limit(1).Find(&r).Error
}

func (r *Reservation) DelReservation(id int64) error {
	return config.DB.Model(&Reservation{}).Where("id = ?", id).Delete(&r).Error
}
